import java.util.Iterator;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;

import com.creawor.km.util.Dom4jUtil;



public class ConConfig {

	private String url = "jdbc:sqlserver://localhost:1433;DatabaseName=sg_market10;SelectMethod=cursor";
 // private String serverName= "localhost";
  //private String portNumber = "1433";
  //private String databaseName= "sg_market10";
  private String userName = "sa";
  private String password = "sa123456";
	
  private ConConfig(){
  	init();
  }
	private void init(){
		java.io.InputStream in=this.getClass().getResourceAsStream("hibernate.cfg.xml");
		Document doc=Dom4jUtil.getDocFromStream(in);
		Element root =doc.getRootElement();
		//System.out.println("rootname="+root.getName());
		Element sesElt=(Element)root.selectSingleNode("session-factory");
		//System.out.println("sesEltname="+sesElt.getName());
		List proList=sesElt.selectNodes("property");
		Iterator it=proList.iterator();
		Element pro=null;
		String name=null;
		while(it.hasNext()){
			pro=(Element)it.next();
			name=pro.valueOf("@name");
			if("connection.url".equalsIgnoreCase(name)){
				url=pro.getTextTrim();
			}
			if("connection.username".equalsIgnoreCase(name)){
				userName=pro.getTextTrim();
			}
			if("connection.password".equalsIgnoreCase(name)){
				password=pro.getTextTrim();
			}
		}
		
	}
	
	
	public static ConConfig getInst(){
		return config;
	}
	private static ConConfig config=new ConConfig();
	
	public static void main(String[]args){
		ConConfig test=new ConConfig();
		test.init();
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
}
